Split links away from tmt.base.core#4901
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors link-related logic by moving Link, Links, and LinkNeedle classes from tmt.base.core to a new tmt.base.links module. Feedback identifies several missing runtime imports for Links and FmfId that will cause NameError exceptions in tmt/base/core.py and tmt/base/links.py. Additionally, update type hints in tmt/utils/jira.py to import directly from the new module instead of using re-exports.
|
|
||
| def _normalize_link(key_address: str, value: _RawLinks, logger: tmt.log.Logger) -> 'Links': | ||
| def _normalize_link(key_address: str, value: '_RawLinks', logger: tmt.log.Logger) -> 'Links': | ||
| return Links(data=value) |
|
|
||
| # Append link with appropriate relation | ||
| links = Links(data=list(cast(list[_RawLink], Story._opt('link', [])))) | ||
| links = Links(data=list(cast(list['_RawLink'], Story._opt('link', [])))) |
| def to_spec(self) -> _RawLinkRelation: | ||
| """ | ||
| Convert to a form suitable for saving in a specification file | ||
|
|
||
| No matter what the original specification was, every link will | ||
| generate the very same type of specification, the ``relation: target`` | ||
| one. | ||
|
|
||
| Output of this method is fully compatible with specification, and when | ||
| given to :py:meth:`from_spec`, it shall create a ``Link`` instance | ||
| with the same properties as the original one. | ||
|
|
||
| [1] https://tmt.readthedocs.io/en/stable/spec/core.html#link | ||
| """ | ||
|
|
||
| spec: _RawLinkRelation = { | ||
| self.relation: self.target.to_spec() if isinstance(self.target, FmfId) else self.target | ||
| } | ||
|
|
||
| if self.note is not None: | ||
| spec['note'] = self.note | ||
|
|
||
| return spec |
There was a problem hiding this comment.
Import FmfId locally within this method. It is used in the isinstance check but is currently only imported inside from_spec, leading to a NameError at runtime.
def to_spec(self) -> _RawLinkRelation:
"""
Convert to a form suitable for saving in a specification file
No matter what the original specification was, every link will
generate the very same type of specification, the relation: target
one.
Output of this method is fully compatible with specification, and when
given to :py:meth:from_spec, it shall create a Link instance
with the same properties as the original one.
[1] https://tmt.readthedocs.io/en/stable/spec/core.html#link
"""
from tmt.base.core import FmfId
spec: _RawLinkRelation = {
self.relation: self.target.to_spec() if isinstance(self.target, FmfId) else self.target
}
if self.note is not None:
spec['note'] = self.note
return spec| if TYPE_CHECKING: | ||
| import jira | ||
|
|
||
| import tmt.base.links |
There was a problem hiding this comment.
| """ | ||
| Search available plans | ||
| """ | ||
| from tmt.base.link import LinkNeedle |
There was a problem hiding this comment.
Typo in module name: tmt.base.link should be tmt.base.links (missing 's'). This will cause an ImportError at runtime when executing the plans() method.
from tmt.base.links import LinkNeedleThis typo is inconsistent with the correct imports on lines 2394 and 2637 in the same file.
| from tmt.base.link import LinkNeedle | |
| from tmt.base.links import LinkNeedle |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
Pull Request Checklist